namespace ESF.MUP.BasePlatform.DbRepository.MSSQL.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class e1 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Applications",
                c => new
                    {
                        Name = c.String(nullable: false, maxLength: 128),
                        Description = c.String(),
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Name);
            
            CreateTable(
                "dbo.ApplicationInstances",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ApplicationId = c.Int(nullable: false),
                        EnvironmentId = c.Int(nullable: false),
                        Application_Name = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Applications", t => t.Application_Name)
                .ForeignKey("dbo.EnvironmentApplicatif", t => t.EnvironmentId, cascadeDelete: true)
                .Index(t => t.Application_Name)
                .Index(t => t.EnvironmentId);
            
            CreateTable(
                "dbo.EnvironmentApplicatif",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Components",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Description = c.String(),
                        Component_Id = c.Int(),
                        ApplicationInstance_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Components", t => t.Component_Id)
                .ForeignKey("dbo.ApplicationInstances", t => t.ApplicationInstance_Id)
                .Index(t => t.Component_Id)
                .Index(t => t.ApplicationInstance_Id);
            
            CreateTable(
                "dbo.Endpoint",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Description = c.String(),
                        Host = c.String(),
                        Port = c.Int(nullable: false),
                        InstanceName = c.String(),
                        ServiceName = c.String(),
                        StartNodeId = c.Int(),
                        NextNodeId = c.Int(),
                        Discriminator = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Endpoint", t => t.StartNodeId)
                .Index(t => t.StartNodeId);
            
            CreateTable(
                "dbo.UriEndpoint",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        Path = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Endpoint", t => t.Id)
                .Index(t => t.Id);
            
            CreateTable(
                "dbo.DatabaseEndpoint",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        DatabaseName = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Endpoint", t => t.Id)
                .Index(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.DatabaseEndpoint", new[] { "Id" });
            DropIndex("dbo.UriEndpoint", new[] { "Id" });
            DropIndex("dbo.Endpoint", new[] { "StartNodeId" });
            DropIndex("dbo.Components", new[] { "ApplicationInstance_Id" });
            DropIndex("dbo.Components", new[] { "Component_Id" });
            DropIndex("dbo.ApplicationInstances", new[] { "EnvironmentId" });
            DropIndex("dbo.ApplicationInstances", new[] { "Application_Name" });
            DropForeignKey("dbo.DatabaseEndpoint", "Id", "dbo.Endpoint");
            DropForeignKey("dbo.UriEndpoint", "Id", "dbo.Endpoint");
            DropForeignKey("dbo.Endpoint", "StartNodeId", "dbo.Endpoint");
            DropForeignKey("dbo.Components", "ApplicationInstance_Id", "dbo.ApplicationInstances");
            DropForeignKey("dbo.Components", "Component_Id", "dbo.Components");
            DropForeignKey("dbo.ApplicationInstances", "EnvironmentId", "dbo.EnvironmentApplicatif");
            DropForeignKey("dbo.ApplicationInstances", "Application_Name", "dbo.Applications");
            DropTable("dbo.DatabaseEndpoint");
            DropTable("dbo.UriEndpoint");
            DropTable("dbo.Endpoint");
            DropTable("dbo.Components");
            DropTable("dbo.EnvironmentApplicatif");
            DropTable("dbo.ApplicationInstances");
            DropTable("dbo.Applications");
        }
    }
}
